package com.itheima;

import java.util.function.Function;

//【函数型接口 - Function】
public class Demo5 {
    public static void main(String[] args) {

        int sum = sum(-100, n -> {
            if (n > 0) {
                return n * (n + 1) / 2;
            } else {
                return -n * (n - 1) / 2;
            }
        });
        System.out.println(sum);

    }

    public static Integer sum(Integer i, Function<Integer, Integer> fun) {
        return fun.apply(i);
    }
}
